<template>
  <div class="polar-container">
    <el-card>
      <div id="polar" :style="{width: width, height: height}"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'polar',
  props:{
    height:{
      type: String,
      default: '200px'
    },
    width:{
      type: String,
      default: '200px'
    }
  },
  mounted () {
    this.$nextTick(() =>{
      this.initCharts()
    })
  },
  methods: {
    initCharts(){
      const charts = echarts.init(document.getElementById('polar'))
      const data = [];
      for (let i = 0; i <= 100; i++) {
        let theta = (i / 100) * 360;
        let r = 5 * (1 + Math.sin((theta / 180) * Math.PI));
        data.push([r, theta]);
      }
      const option = {
        title: {
          text: 'Two Value-Axes in Polar'
        },
        legend: {
          data: ['line'],
          left: 'right'
        },
        polar: {},
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
        angleAxis: {
          type: 'value',
          startAngle: 0
        },
        radiusAxis: {},
        series: [
          {
            coordinateSystem: 'polar',
            name: 'line',
            type: 'line',
            data: data
          }
        ]
      };
      charts.setOption(option);
    },
  }
}
</script>

<style scoped>

</style>
